<?php

class PlayerController extends BaseController
{
    private $req;

    public function init()
    {
        $this->req = $this->getRequest();
        if ($this->req->isXMLHttpRequest()) {
            Zend_Controller_Action_HelperBroker::getStaticHelper('viewRenderer')->setNoRender(true);
            $layout = Zend_Layout::getMvcInstance();
            if ($layout instanceof Zend_Layout) {
                $layout->disableLayout();
            }
        }
        $this->view->breadcrumb = array(array(
            'url' => '/player/index',
            'name' => '球队管理',
        ));
    }

    /**
     * 球队列表
     */
    public function indexAction()
    {
        $player_biz = new \Biz\Player();
        $size = Page::ValidatePageSize($this->req->get('pageSize'), '/player/index'); //每页显示条数
        $size = 50;
        $now = $this->req->get('p') ? $this->req->get('p') : 1;//当前页数
        $where = '';
        $list_result = $player_biz->getPlayerList($where, $now, $size);
        $page = new Page($list_result['total'], $size, $now, '/player/index?', 2);

        //保存数据到Redis
//        if($list_result['lists']){
//            $redisData = array();
//            foreach ($list_result['lists'] as $key => $item){
//                $redisData[$key]['id'] = $item['id'];
//                $redisData[$key]['player_name'] = $item['player_name'];
//                $redisData[$key]['icon_url'] = $item['icon_url'];
//            }
//            $redis_instance = \Util\Redis::getInstance();
//            $redis_instance->set('ziyan_player_list',json_encode($redisData));
//        }


        $this->view->size = $size;
        $this->view->now = $now;
        $this->view->pageStr = $page->showPage();
        $this->view->list_result = $list_result['lists'];
        $this->view->breadcrumb = array(
            array(
            'name' => '球队列表',
        ));
    }
}